﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;
using LibraryO2S;

public partial class Administrator_Category : System.Web.UI.Page
{

    ConnectSQL cnts = new ConnectSQL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
            // divMessage.InnerHtml = O2S_Message.Success("Cảnh Báo", "Chưa Có dữ liệu trong mục này!");
        }
    }

    private void LoadData()
    {
        try
        {
            rptData.DataSource = cnts.GetTableWithCommandText("SELECT * FROM tblProductCategories");
            rptData.DataBind();
        }
        catch
        {
            divMessage.InnerHtml = O2S_Message.Warning("Cảnh Báo", "Chưa Có dữ liệu trong mục này!");
        }
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        try
        {

            string del_list = hdfCheck.Value;
            string[] sp_list = del_list.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < sp_list.Length; i++)
            {
                cnts.ExcutedCMD("delete from tblProductCategories where CATEGORY_ID=" + sp_list[i]);
            }
            LoadData();
        }
        catch (Exception ex)
        {

            divMessage.InnerHtml = O2S_Message.Error("Cảnh Báo", "Phát hiện lỗi! " + ex.Message);
        }

    }
    protected void btnAdnew1_Click(object sender, EventArgs e)
    {
        Response.Redirect("CategoryAdd.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("CategoryAdd.aspx");
    }
    protected void btnUpdateDisplayOrder_Click(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in rptData.Items)
        {
            HtmlAnchor html = (HtmlAnchor)item.FindControl("a_Child");
            TextBox tb = (TextBox)item.FindControl("txtA");
            string category_id = html.Title.Trim(); ;
            string sql_Text = "update tblProductCategories set DISPLAY_ORDER=" + tb.Text + " where CATEGORY_ID=" + category_id;
            cnts.ExcutedCMD(sql_Text);

        }
        divMessage.InnerHtml = O2S_Message.Success("Hệ thống", "Thực hiện thành công");
    }
    protected void btnUpdate2_Click(object sender, EventArgs e)
    {
        btnUpdateDisplayOrder_Click(sender, e);
    }
}